package main

import (
	"fmt"
	"log"
	"preprocessing/correlation"
	gainratio "preprocessing/gainRatio"
	parsedata "preprocessing/parseData"

	"gonum.org/v1/gonum/mat"
)

// сразу и транспонирует для дальнейшего удобства работы со слайсами
func denseToSlice(matrix *mat.Dense) [][]float64 {
	rows, cols := matrix.RawMatrix().Rows, matrix.RawMatrix().Cols

	nMatrix := make([][]float64, cols)
	for i := 0; i < cols; i++ {
		nMatrix[i] = make([]float64, rows)
	}

	for i := 0; i < cols; i++ {
		for j := 0; j < rows; j++ {
			nMatrix[i][j] = matrix.At(j, i)
		}
	}

	return nMatrix
}

func main() {
	matrix, names, err := parsedata.ParseCSV("./Laptop_price.csv")
	//matrix, names, err := parsedata.ParseCSV("./test.csv")

	if err != nil {
		log.Println(err)
		return
	}

	for {
		corr := correlation.CorrMatrix(matrix)
		correlation.PrintCorrMatrix(corr, names)
		correlation.CreateHeatMap(corr)

		fmt.Println("Хотите удалить параметр? (y/n)")

		var resp rune
		fmt.Scanf("%c", &resp)
		if resp != 'y' {
			break
		}

		fmt.Println("Введите номер столбца:")
		var column int
		fmt.Scan(&column)
		column--

		rows, cols := matrix.RawMatrix().Rows, matrix.RawMatrix().Cols
		//data := matrix.RawMatrix().Data

		tmp := make([]float64, 0)

		//fmt.Println(matrix)

		for i := 0; i < rows; i++ {
			for j := 0; j < cols; j++ {
				if j == column {
					continue
				}
				tmp = append(tmp, matrix.At(i, j))
			}
		}

		matrix = mat.NewDense(rows, cols-1, tmp)
		//fmt.Println(matrix)
		names = append(names[:column], names[column+1:]...)

	}

	/////////////////////////////////
	data := denseToSlice(matrix)

	result := gainratio.CalcGeinRatio(data, len(data)-1)

	fmt.Println("\n Значения Gain Ratio:")
	for i := 0; i < len(result); i++ {
		fmt.Println(names[i], ":", result[i])
	}

	//функция для отрисовки графика
	CreateGraph(result)
	// вот тут
}
